package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {
  @Autowired
  LabelInfoMapper labelInfoMapper;
  @Autowired
  GraphInfoMapper graphInfoMapper;

  @Autowired
  RoomInfoMapper roomInfoMapper;

  @Autowired
  FacilityInfoMapper facilityInfoMapper;
    @Override
    public ApartmentItemVo getApartmentInfoById(Long apartmentId) {
        //查询公寓的基本信息
        ApartmentInfo apartmentInfo = this.getById(apartmentId);

        //公寓的标签
        List<LabelInfo> labelInfoList=   labelInfoMapper.selectLabelByApartmentId(apartmentId);

        //公寓的标签
        List<GraphInfo> graphVoList=  graphInfoMapper.selectGraphInfoByIdAndType(apartmentId,ItemType.APARTMENT);

        //当前公寓最便宜的房间价格(最小租金)
        BigDecimal minRent=  roomInfoMapper.selectMinRentByApartmentId(apartmentId);

        ApartmentItemVo apartmentItemVo=new ApartmentItemVo();
        BeanUtils.copyProperties(apartmentInfo,apartmentItemVo);
        apartmentItemVo.setLabelInfoList(labelInfoList);
        apartmentItemVo.setGraphVoList(graphVoList);
        apartmentItemVo.setMinRent(minRent);

        return apartmentItemVo;
    }

    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        ApartmentInfo apartmentInfo = this.getById(id);
        List<GraphInfo> graphVoList=graphInfoMapper.selectGraphInfoByIdAndType(id,ItemType.APARTMENT);
        List<LabelInfo> labelInfoList=labelInfoMapper.selectLabelByApartmentId(id);
        List<FacilityInfo> facilityInfoList=facilityInfoMapper.selectFacilityByApartmeById(id);
        BigDecimal minRent=roomInfoMapper.selectMinRentByApartmentId(id);
        Boolean isDelete=apartmentInfo.getIsDeleted()==1;

        ApartmentDetailVo apartmentDetailVo=new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentInfo,apartmentDetailVo);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setIsDelete(isDelete);
        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setMinRent(minRent);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        return apartmentDetailVo;
    }
}




